package cn.xd.base.persistence.mps.impl;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.xd.base.persistence.dos.GlobalAppUserDO;
import cn.xd.base.persistence.mapper.GlobalAppUserMapper;
import cn.xd.base.persistence.mps.GlobalAppUserMpService;
import cn.xd.common.enums.common.CommonStatusEnum;
import cn.xd.core.response.ObjectResult;
import cn.xd.core.service.impl.BasicMpServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chenyh
 * @since 2023-09-08
 */
@Service
public class GlobalAppUserMpServiceImpl extends BasicMpServiceImpl<GlobalAppUserMapper, GlobalAppUserDO> implements GlobalAppUserMpService {

    @Override
    public ObjectResult<GlobalAppUserDO> findByPhone(String phone, Long neId) {
        if (StrUtil.isBlank(phone)) {
            return ObjectResult.of(null);
        }
        return this.getOneForLimitOneResult(new LambdaQueryWrapper<GlobalAppUserDO>()
                .ne(ObjUtil.isNotNull(neId), GlobalAppUserDO::getId, neId)
                .eq(GlobalAppUserDO::getPhone, phone)
                .ne(GlobalAppUserDO::getStatus, CommonStatusEnum.DELETED.getCode()));
    }

}
